package software.agileCourse2013.KillerGame.web.Socket;

import java.util.Random;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;

import software.agileCourse2013.KillerGame.service.models.UserModel;
import software.agileCourse2013.KillerGame.web.MessageBound.ChatMessageInbound;

@WebServlet("/chat")
public class ChatWebSocketServlet extends WebSocketServlet {
  /**
   * 
   */
  private static final long serialVersionUID = -1058445282919079067L;

  @Override
  protected StreamInbound createWebSocketInbound(String arg0,HttpServletRequest request) {
	  UserModel user = new UserModel();
	  String ids= request.getParameter("id");
	  System.out.print(ids);
	  Random r = new Random();
	  String id = String.valueOf(r.nextInt(50));
	  user.setId(id);
	  user.setName("haha");
	  request.getSession().setAttribute("User", user);
	  UserModel user1 =  (UserModel) request.getSession().getAttribute("User");
    return  new ChatMessageInbound(user1);
  }

  
}